package com.way.designpatterncodepratice.factory.simpleFactory;

import com.way.designpatterncodepratice.factory.base.CheesePizza;
import com.way.designpatterncodepratice.factory.base.FruitPizza;
import com.way.designpatterncodepratice.factory.base.Pizza;

import java.util.Scanner;

/**
 * @author liangliwei 80551025
 * @description
 * @date 2020-06-22
 */
public class PizzaStore {

    private SimplePizzaFactory simplePizzaFactory;
    Pizza pizza;

    public PizzaStore(SimplePizzaFactory simplePizzaFactory) {
        this.simplePizzaFactory = simplePizzaFactory;
    }

    public void orderPizza(){
        while (true){
            String pizzaType = getType();
            pizza = simplePizzaFactory.cretePizza(pizzaType);

            /**
             * 输出pizza制作过程
             */
            if(pizza!=null){
                pizza.prepare();
                pizza.cut();
                pizza.bake();
                pizza.box();
            }else{
                System.out.println("订购失败");
                break;
            }
        }
    }

    private String getType() {
        Scanner scanner = new Scanner(System.in);
        String pizzaType = scanner.next();
        return pizzaType;
    }
}
